<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    var array = function (arr) {
      for (let i = 0; i < arr.length; i++) {
        if (arr[i] == 0) {
          arr.splice(i, 0, 0)
          arr.pop()
          //当添加了一个元素，需要跳过一个index，否者一直添加 0
          i++
        }
      }
      return arr
    };
    console.log(array([1, 0, 2, 3, 0, 4, 5, 0]))
  </script>
</body>

</html>